// 接口定义
const fontEncode = require('./dataManager');
const [path, fs] = [require('path'), require('fs')];
var rule;
var pathname = path.join(__dirname, "../../rule.json");
module.exports = {
  "GET /api/numRender": async (ctx, next) => {
    try {
      var data = fs.readFileSync(pathname, "utf-8");
      ruleJson = JSON.parse(data);
      rule = ruleJson.data.rule;
    } catch (error) {
      console.log("fail: " + error);
    }
    var data = {
      code: 200,
      message: "success",
      data: {
        name: "永远的18岁",
        year: fontEncode("2003", rule),
        month: fontEncode("06", rule),
        day: fontEncode("06", rule),
        analysis: rule
      }
    }
    ctx.set("Access-Control-Allow-Origin", "*");
    ctx.response.type = "application/json";
    ctx.response.body = data;
  },
  "GET /api/charRender": async (ctx, next) => {
    try {
      var data = fs.readFileSync(pathname, "utf-8");
      ruleJson = JSON.parse(data);
      rule = ruleJson.data.rule;
    } catch (error) {
      console.log("fail: " + error);
    }
    var data = {
      code: 200,
      message: "success",
      data: {
        title: fontEncode("人长得好看，工资2万，九州钱，公司造", rule),
        analysis: rule
      }
    }
    ctx.set("Access-Control-Allow-Origin", "*");
    ctx.response.type = "application/json";
    ctx.response.body = data;
  },
};
